<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: {2021/1/15}
 * Time: {20:59}
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\lib;


use app\common\lib\sms\AliSms;
use app\common\lib\sms\BaiduSms;
use app\common\lib\sms\JdSms;
use think\Exception;

class ClassArr
{
    /**
     * @return string[]
     */
    public static function SmsClassStat(): array
    {
        return [
            "baidu" => BaiduSms::class,
            "jd" => JdSms::class,
            "ali" => AliSms::class
        ];
    }

    /**
     * @param $key
     * @param $array
     * @param array $param
     * @param false $needInstance
     * @return mixed|object
     * @throws Exception
     * @throws \ReflectionException
     */
    public static function initClass($key, $array, $param = [], $needInstance = false)
    {
        if (!array_key_exists($key, $array)) {
            throw new Exception("未定义 {$key} 方法");
        }
        $className = $array[$key];
        // todo ReflectionClass(A) 建立反射类
        return $needInstance == true ? (new \ReflectionClass($className))->newInstanceArgs($param) : $className;
    }

}